package com.smmisia.article.controller;

import com.smmisia.article.request.CommentAddRequest;
import com.smmisia.article.response.commentResponse;
import com.smmisia.article.service.CommentService;
import com.smmisia.common.Result.Result;
import groovy.util.logging.Slf4j;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
@Slf4j
@Tag(name = "评论管理")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 评论列表
     * @param articleId
     * @param type
     * @return
     */
    @GetMapping("/list")
    @Operation(summary = "评论列表")
    public Result<List<commentResponse>> list(@RequestParam(value = "articleId") int articleId,
                                              @RequestParam(value = "type") int type) {

        return commentService.commentList(articleId, type);
    }

    @PostMapping("/add")
    @Operation(summary = "添加评论")
    public Result<String> add(@Valid @RequestBody CommentAddRequest request) {
        return commentService.add(request);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除评论")
    public Result<String> delete(@RequestParam(value = "id") int id) {
        return commentService.delete(id);
    }

    @GetMapping("/like")
    @Operation(summary = "点赞")
    public Result<String> like(@RequestParam(value = "id") int id) {
        return commentService.like(id);
    }

}
